<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="org.json.*"%>
<%@ page import="org.jbpm.graph.def.*"%>
<%@ page import="org.jbpm.graph.exe.*"%>
<%@ page import="org.jbpm.taskmgmt.def.*"%>
<%@ page import="com.gzgi.framework.*"%>
<%@ page import="com.gzgi.framework.el.*"%>
<%@ page import="com.gzgi.framework.util.*"%>
<%@ page import="com.gzgi.framework.sys.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.util.*"%>
<%@ page import="com.gzgi.workflow.jbpm.model.*"%>
<%@ page import="com.gzgi.workflow.jbpm.context.*"%>
<%@ page import="com.gzgi.workflow.jbpm.config.*"%>
<%@ page import="com.gzgi.workflow.jbpm.container.*"%>
<%@ page import="com.gzgi.workflow.jbpm.datafield.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.*"%>
<%@ page import="com.gzgi.workflow.jbpm.mgmt.product.*"%>
<%
    JSONObject obj = new JSONObject();   
    JSONArray array = new JSONArray();   
	Map params = RequestUtil.getParameterMap(request);
	int start = ParamUtil.getInt(params, "start");
	int limit = ParamUtil.getInt(params, "limit");
	int currPageNo = 1;
	if (start > 0 && limit > 0) {
			currPageNo = start / limit + 1;
	}

	ProductController handler = (ProductController)ControllerFactory.getController("productController");
	Page jpage = handler.getProducts(currPageNo, limit, params);
	List rows = jpage.getRows();
    if(rows != null && rows.size() > 0){
		    int index = 0;
		    Iterator iterator = rows.iterator();
		    while(iterator.hasNext()){
			        index++;
                    Product p = (Product)iterator.next();
				    JSONObject row = new JSONObject();   
					row.put("sortNo", String.valueOf(index));
					row.put("productId", p.getProductId());
					row.put("createDate", DateTools.getDate(p.getCreateDate()));
					if(p.getAuditDate() != null){
					   row.put("auditDate", DateTools.getDate(p.getAuditDate()));
					}
					if(p.getProductDate() != null){
					   row.put("productDate", DateTools.getDate(p.getProductDate()));
					}
					row.put("processInstanceId", p.getProcessInstanceId());
					row.put("productName", p.getProductName());
					row.put("productCode", p.getProductCode());
					row.put("processName", p.getProcessName());
					row.put("manufacturer", p.getManufacturer());
					row.put("description", p.getDescription());
					row.put("quantity", p.getQuantity());
					row.put("price", p.getPrice());
					row.put("status", p.getStatus());
					row.put("wfStatus", p.getWfStatus());
					row.put("x_rowNum", new Integer(jpage.getCurrRowNo()+index-1));
					switch(p.getStatus()){
						case 30:
							row.put("statusName", "<b><font color='blue'>已提交</font></b>");
							break;
						case 40:
							row.put("statusName", "<b><font color='blue'>审核中</font></b>");
							break;
						case 50:
							row.put("statusName", "<b><font color='green'>审核通过</font></b>");
							break;
						case -1:
							row.put("statusName", "<b><font color='red'>已退回</font></b>");
							break;
						default:
							row.put("statusName", "<b>未提交</b>");
							break;
					}
					array.put(row);   
		}
		obj.put("totalCount", new Integer(jpage.getTotalPageCount()));
	}

  obj.put("rows", array);   
  out.print(obj);   
%>